<?php namespace Common\Model;
use \Hdphp\Model\Model;

	class brand extends Model
	{
		protected $table = "brand";
		protected $validate = array(
			array("bname","required","请输入品牌名",3,3),
			array("scort","num:0,10000000","排序必须是数字",3,3)
		);
		protected $auto = array(
			array("sendtime","time","function",3,1),
			array("thumb","b_img","method",3,3),
			//array("former_image","for_img","method",3,3),
			array("resettime","time","function",3,2),
		);
		
		//
		
		//t_img
		protected function b_img()
		{
			if(isset($_POST['thumb'])){
				return $_POST['thumb'];
			}
			$path = "Upload/brand/";
			$file = Upload::path($path)->type('jpg,jpeg,png')->size(100000)->make();
			if($file){
				$thumbimg = Image::thumb($file[0]["path"],"Upload/brand_thumb/" . $file[0]["basename"],96,46,5);
				return $thumbimg;
			}else{
				return "";
			}
		}
		/*
		 * 添加
		 * */
		public function addbrand()
		{
			if(!$this->create()) return FALSE;
			return $this->add();
		}
		/*
		 * 编辑
		 * */
		public function resetbrand()
		{
			if(!$this->create()) return FALSE;
			if(isset($_FILES["thumb"]) && $_FILES['thumb']['error']==4){
				$this->error="请上传图片";
				return FALSE;
			}
			return $this->save();
		}
		/*
		 * 删除
		 * */
		public function del($bid)
		{
			
			return $this->where("bid",$bid)->delete();
		}
	}
